var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');

var index = require('./routes/index');

var app = express();

// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');

//app.use(logger('dev'));

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
var deviceprocess=require('./routes/deviceprc');
app.all('/setinterval', deviceprocess.setinterval);

// catch 404 and forward to error handler
app.use(function(req, res, next) {
  var err = new Error('请求URL非法');
  err.status = 200;
  res.end();
  //next(err);
});

var http = require('http');
var config = require('./config');
app.set('ip', config.static_host);
app.set('port', config.static_port);
var server=http.createServer(app).listen(app.get('port'), app.get('ip'), function() {
    console.info('+++++++++++++++++++++++++++++++++++++++++++++++++++');
    for(key in config) {
        if(!(typeof (config[key]) == "function")) {
            console.info(key + '\t\t= ' + config[key]);
        }
    }
    console.info('+++++++++++++++++++++++++++++++++++++++++++++++++++');
    console.info('启动服务完成，监听IP: '+ app.get('ip') +', 端口: ' + app.get('port'));
    console.info('+++++++++++++++++++++++++++++++++++++++++++++++++++');
});

deviceprocess.process(server);